import * as contains from './actionTypes'

import axios from 'axios'

import {fromJS } from 'immutable'

// 把数组转化为 fromjs对象
const changeList = (data)=>({
    type:contains.CHANGE_LIST,
    data:fromJS(data),
    totalPage:Math.ceil(data.length/10)

})
export const sreachRocus = ()=>({
    type:contains.SREACH_FOCUS
})

export const sreachBlur = ()=>({
    type:contains.SREACH_BLUR
})
export const mouseEnter = ()=>({
    type:contains.MOUSE_ENTER
})
export const mouseLeave = ()=>({
    type:contains.MOUSE_LEAVE
})

export const changePage = (page)=>({
    type:contains.CHANGE_PAGE,
    page:page
})

// 获取list列表数据
export let getList =()=>{
    return (dispatch)=>{
        axios.get('api/headerList.json').then((res)=>{
         if(res.data.success){
             const action = changeList(res.data.list);
             dispatch(action)
         }

        }).catch((e)=>{
            console.log('error')
        })
    }
};